/**
 * 用类实现游戏中的英雄，以及攻击行为
 */

class Champion {
  // 构造函数
  constructor({name, health, fire}) {
    this.name = name;
    this.health = health;
    this.fire = fire;
  }

  attack(champion){
    if( this.health < 1){
      console.log('死人攻击无效。');
      return;
    }
    console.log( this.name, '攻击', champion.name, '掉血', this.fire);
    champion.reduce(this.fire);
  }

  reduce(fire){
    this.health -= fire; // this.health = this.health - fire;
    if( this.health < 1 ) {
      console.log(this.name, '死了');
    }
  }

  print(){
    console.log(this.health);
  }
};

const dodo = new Champion({
  name: 'dodo',
  health: 100,
  fire: 100,
});

const dabao = new Champion({
  name: 'dabao',
  health: 120,
  fire: 120,
});

const sufen = new Champion({
  name: 'sufen',
  health: 200,
  fire: 80,
});

dabao.attack( dodo );
dodo.print();
sufen.attack( dabao );
dabao.print();

dodo.attack( dabao );
dabao.print();